from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')

# 定位元素 xpath标签和属性
kw = driver.find_element(By.XPATH, '//input[@id="kw"]')
print(kw.get_attribute('outerHTML'))

kw = driver.find_element(By.XPATH, '//input[@class="s_ipt"]')
print(kw.get_attribute('outerHTML'))

kw = driver.find_element(By.XPATH, '//*[@maxlength="255"]')
print(kw.get_attribute('outerHTML'))

input_lists = driver.find_elements(By.XPATH, '//input')
for ipt in input_lists:
    print(ipt.get_attribute('outerHTML'))

# 退出浏览器
driver.quit()